<style scoped>
    .layout{
        border: 1px solid #d7dde4;
        background: #f5f7f9;
        position: relative;
        border-radius: 4px;
        overflow: hidden;
    }
    .layout-breadcrumb{
        padding: 10px 15px 0;
    }
    .layout-content{
        min-height: 560px;
        margin: 15px;
        overflow: hidden;
        background: #fff;
        border-radius: 4px;
    }
    .layout-content-main{
        padding: 10px;
    }
    .layout-copy{
        text-align: center;
        padding: 10px 0 20px;
        color: #9ea7b4;
    }
    .layout-menu-left{
        background: #464c5b;
    }
    .layout-header{
        height: 60px;
        background: #fff;
        box-shadow: 0 1px 1px rgba(0,0,0,.1);
    }
    .layout-logo-left{
        width: 90%;
        height: 30px;
        background: #5b6270;
        border-radius: 3px;
        margin: 15px auto;
    }
    .layout-ceiling-main a{
        color: #9ba7b5;
    }
    .layout-hide-text .layout-text{
        display: none;
    }
    .ivu-col{
        transition: width .2s ease-in-out;
    }
</style>
<template>
<div>
      <div v-if="login">
    <div class="layout" :class="{'layout-hide-text': spanLeft < 5}">
        <Row type="flex">
            <i-col :span="spanLeft" class="layout-menu-left">
                <Menu active-key="1" theme="dark" width="auto">
                    <div class="layout-logo-left"></div>
                   
                    <Menu-item name="1">
                        <router-link to='/' exact active-class="active">
                        <Icon type="home" :size="iconSize"></Icon>    
                           <span class="layout-text">首页 </span>
                       </router-link>
                    </Menu-item>
                   
                    <Menu-item name="2">
                      <Icon type="ios-person" :size="iconSize"></Icon>
                        <span class="layout-text">
                          
                          <router-link to='/user' active-class="active">用户模块</router-link>
                          </span>
                    </Menu-item>
                    <Menu-item name="3">
                        <Icon type="ios-analytics" :size="iconSize"></Icon>
                         <router-link to='/classify' active-class="active">分类模块</router-link>
                    </Menu-item>
                    <Menu-item name="4">
                        <Icon type="social-hackernews" :size="iconSize"></Icon>
                         <router-link to='/news' active-class="active">新闻模块</router-link>
                    </Menu-item>
                    <Menu-item name="5">
                        <Icon type="upload" :size="iconSize"></Icon>
                       <router-link to='/upload' active-class="active">上传模块</router-link>
                    </Menu-item> <Menu-item name="6">
                        <Icon type="upload" :size="iconSize"></Icon>
                      <router-link to='/production' active-class="active">产品模块</router-link>
                    </Menu-item>
                </Menu>
            </i-col>
            <i-col :span="spanRight">
                <!-- <div class="layout-header">
                    <i-button type="text" @click="toggleClick">
                        <Icon type="navicon" size="32"></Icon>
                    </i-button>
                </div> -->
                <div class="layout-breadcrumb">
                    <Breadcrumb>
                        <Breadcrumb-item href="#">首页</Breadcrumb-item>
                        <Breadcrumb-item href="#">应用中心</Breadcrumb-item>
                        <Breadcrumb-item>管理界面</Breadcrumb-item>
                    </Breadcrumb>
                </div>
                <div class="layout-content">
                    <div class="layout-content-main">
                      <router-view></router-view>
                    </div>
                </div>
                <div class="layout-copy">
                    1995-2017 &copy; 范哲文
                </div>
            </i-col>
        </Row>
    </div>
      </div>
      <div v-else>
        <Form ref="formInline" :model="formInline" inline>
            <FormItem prop="name">
                <Input type="text" v-model="formInline.name" @on-enter="handleSubmit('formInline')" placeholder="Username">
                    <Icon type="ios-person-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem prop="password">
                <Input type="password" v-model="formInline.password" @on-enter="handleSubmit('formInline')" placeholder="Password">
                    <Icon type="ios-locked-outline" slot="prepend"></Icon>
                </Input>
            </FormItem>
            <FormItem>
                <Button type="primary" @click="handleSubmit('formInline')">登录</Button>
            </FormItem>
        </Form>
    </div>
      </div>
</template>
<script>
import md5 from 'crypto-js/md5'
 import {mapGetters,mapActions} from 'vuex';
    export default {
        data () {
            return {
                spanLeft: 5,
                spanRight: 19,
                formInline: {
                    name: '',
                    password: ''
                },
            }
             
        },
        computed: {
             ...mapGetters(['login']),
            iconSize () {
                return this.spanLeft === 5 ? 14 : 24;
            }
        },
        methods: {
             ...mapActions(['checkLogin']),
            toggleClick () {
                if (this.spanLeft === 5) {
                    this.spanLeft = 2;
                    this.spanRight = 22;
                } else {
                    this.spanLeft = 5;
                    this.spanRight = 19;
                }
            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                         this.formInline.password=md5( this.formInline.password).toString();
                        this.$http.post(`http://localhost:3000/users/checkLogin/`,this.formInline)
                        .then(res=>{
                            console.log(res);
                            if(res.data.status==404){
                                     this.$Message.info(res.data.msg);
                            }else{      
                                sessionStorage.login=true;
                                this.checkLogin( sessionStorage.login);    
                                this.$Message.success('登录成功');
                            }
                        })                      
                        // localStorage.login = true;                       
                    } else {
                        this.$Message.error('表单验证失败!');
                    }
                })
            }
        },
          created(){
            this.checkLogin( sessionStorage.login); 
        }
      
    }
</script>